<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    table{
        margin:  0 auto;
        border-collapse: collapse;
    }
</style>
<body>
    <table border='1' width="600px" height="50px">
        <tr>
<td colspan="4"  style="background-color:skyblue;"><input type="checkbox" id="quanxuan">全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商家&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价格</td>
        </tr>
        <tr>
<td align="center"><input type="checkbox" class="ck"></td>
<td align="center">小米手机</td>
<td align="center">小米</td>
<td align="center">￥1999</td>
        </tr>
        <tr>
<td align="center"><input type="checkbox" class="ck"></td>
<td align="center">小米净水器</td>
<td align="center">小米</td>
<td align="center">￥4999</td>
        </tr>
        <tr>
<td align="center"><input type="checkbox" class="ck"></td>
<td align="center">小米电视</td>
<td align="center">小米</td>
<td align="center">￥5999</td>
        </tr>
    </table>

<script>
    const quanxuanbtn = document.querySelector('#quanxuan')
    const ck = document.querySelectorAll('.ck')
    quanxuanbtn.addEventListener('click',function(){
        for (let i = 0 ;i <ck.length ; i++){
            ck[i].checked = quanxuanbtn.checked
        } 
    })

    for(let i = 0 ; i <ck.length ; i++){
        ck[i].addEventListener('click',function(){
            const cked = document.querySelectorAll('.ck:checked')
            quanxuanbtn.checked = cked.length === ck.length
        })
    }
</script>
</body>
</html>